/**
 * 系统底层公共方法自定义入口
 * yangzeng 20190523*/
const defaultParam = {
    /*** 业务内参数路径
     *** start ***/
    //配置文件地址
    base_config: "/config/base_config.json",
    //下拉公共数据列表
    dropDownList: "/config/drop_down_list.json",
    //服务器端维护的下拉列表数据地址
    select_path: "/basicbusinessservice/util/getListByType",
    //路由文件地址
    path_url: "/config/base_url.json",
    //表单验证规则文件地址 
    vuetable: "vuetable.json",
    g6_data: "/data/G6.json",
    /*** end ***/

    //路由跳转参数
    data: null,
    //公共抄表员查询序号配置
    operatorIndex:[52,53,53,54,56,56],
    //其他菜单序号
    menuIndex:[66],
    //登录弹窗
    login_index: 0
};

/**
 * 简单的元素查找功能
 * 注：当前检索仅仅支持id、className、tagName，三种方式，返回元素本身的格式对象
 * @Author yangzeng
 * 20190723 */
defaultParam.find = function(el){
    if(el.indexOf(".") > -1) {
        let str = el.split(".")[1];
        return document.getElementsByClassName(str);
    }else if(el.indexOf("#") > -1){
        let str = el.split("#")[1];
        return document.getElementById(str);
    }else{
        return document.getElementsByTagName(el);
    }
};

/**
 * cookie的获取
 * @param key 指定获取的键值
 * @Author yangzeng
 * 20200812 */
defaultParam.getCookie = function(key){
    let cookie = document.cookie;
    let cookieArr = cookie.split(";");
    if(!!key){
        let _value = null;
        for(let i in cookieArr){
            if(cookieArr[i].indexOf(key+"=") != -1){
                _value = (cookieArr[i]).split("=")[1];
            }
        }  
        return _value; 
    } else {
        return cookie;
    }
}; 

/**
 * 设置cookie
 * @param key cookie键值
 * @param value cookie参数
 * @Author yangzeng
 * 20200812 */
defaultParam.setCookie = function(key, value){
    if(!!key){
        let str = key + "=" + escape(value);
        let date = new Date();
        axios.get(this.base_config).then(res => {
            if(res.status == 200){
                let data = res.data;
                let tm = data.login.max_login_timer;
                date.setTime(date.getTime() + tm);
                str += "; expires=" + date.toGMTString();
                str += "; path=/";
                document.cookie = str;
            }
        })
    }
} 

/**
 * 验证当前用户是否已经登陆，若没有登陆则强制跳转登陆进行登陆
 * @Author yangzeng
 * 20190617 */
defaultParam.isLogin = function(self){
    let access_token = window.localStorage.getItem("user_token");
    let sys = this.getCookie("sys");
    let _this = this;
    if(sys == null) {
        if(_this.login_index == 0){
            _this.login_index = 1;
            _this.confrirm(self, {
                message: "登录超时，请重新进行登录！",
                ok: function(){
                    _this.login_index = 0;
                    _this.logout(self);
                },
                // cancel: function(){
                //     _this.login_index = 0;
                //     _this.logout(self);
                // },
                closeOnClickModal: false,
                showClose: false,
                closeOnPressEscape: false,
            })
        } else return false;
    } else{
        if (!!access_token)  return true;
        else{
            _this.confrirm(self, {
                message: "用户信息丢失，请重新登录！",
                ok: function(){_this.logout(self)},
                // cancel: function(){_this.logout(self)},
                closeOnClickModal: false,
                showClose: false,
                closeOnPressEscape: false,
            })
            _this.logout(self);
            return false;
        }  
    }
};

/**
 * 刷新本地的用户从存储信息
 * @Author yangzeng
 * 20190724 */
defaultParam.loadUserInfo = function(self){
    self.$my.getSource(self, self.$my.path_url).then(_ => {
        let path = _.data.baseUrl + _.data.sysUrl.getUser;
        let access_token = window.localStorage.getItem("user_token");
        self.$axios.post(path+"?access_token="+access_token).then(res=>{
            //console.log(res.data);
            //localStorage.setItem("userinfo",JSON.stringify(res.data));
        }).catch(err=>{
            console.log(err);
        })
    })
}
/**
 * 自定义post请求，对token 包含对token的验证
 * @param self  当前调用的环境对象本身
 * @param url   请求发送地址
 * @param data  请求附带参数
 * @param successCallback   成功回调
 * @param errorCallback 异常回调
 * @param type 导出时的参数设置，若存在则为导出针对接口返回格式
 * @Author yangzeng 20190603 */
defaultParam.post = function(self,url, data,successCallback,errorCallback,isTable){
    let _this = this;
    //判断登录
    if(_this.isLogin(self) && !!url){
        let userInfo = JSON.parse(window.localStorage.getItem("userinfo"));
        if(!!userInfo.accessToken && userInfo.userId){
            _this.getSource(self, _this.base_config).then(res => {
                if(res.status == 200){
                    let config = res.data;
                    let timer = (new Date()).getTime();
                    let token = self.$md5(userInfo.accessToken+config.app.appScrect+config.app.appName+timer);
                    // 若url 存在param 参数，则对参数进行转义（ie兼容问题）
                    /******************** IE 兼容处理 Start ***********************/
                    let urlStr = url.toString();
                    let rel =/.*[\u4e00-\u9fa5]+.*$/;
                    let newUrl = urlStr.split("?")[0];
                    let oldParam = urlStr.split("?")[1];
                    if(!!oldParam){
                        let params = oldParam.split("&");
                        let newParam = "";
                        for(let i = 0; i< params.length; i++){
                            if(i == 0){
                                if(rel.test(params[i].split("=")[1])){
                                    newParam = newParam + params[i].split("=")[0] + "=" + encodeURI(params[i].split("=")[1])
                                } else newParam = params[i];
                            } else {
                                if(rel.test(params[i].split("=")[1])){
                                    newParam +=  "&" + params[i].split("=")[0] + "=" + encodeURI(params[i].split("=")[1]);
                                } else newParam += "&" + params[i];
                            }
                        }
                        // 对地址进行合成
                        _this.post_Reset(self, newUrl + "?" + newParam, data,successCallback,errorCallback,isTable, userInfo, config, timer, token);
                    } else _this.post_Reset(self, url, data,successCallback,errorCallback,isTable, userInfo, config, timer, token);
                    /******************** IE 兼容处理 End   ***********************/
                }
            });
        }else _this.errorMsg(self, "登录信息异常，请确认参数是否正确！");
    }
};
defaultParam.post_Reset = function(self,url, data,successCallback,errorCallback,isTable, userInfo, config, timer, token){
    let urlStr = url.toString();
    //地址参数的报装、判断当前是否存在param参数类型
    if((urlStr.split("?") instanceof Array) && (urlStr.split("?")).length > 1) urlStr += "&token="+token;
    else    urlStr+= "?token=" + token;
    urlStr += "&accessToken="+userInfo.accessToken+"&userId="+userInfo.userId+
        "&timeStamp="+timer+"&appSecret="+config.app.appScrect;
    urlStr += "&orgId="+userInfo.orgId;
    //请求参数设置
    let loading
    if(!isTable){
        loading = this.openLoading("请稍候...");
    }
    let opts = {
        //请求类型
        method: "post",
        //请求地址处理
        url: config.base.baseUrl + urlStr,
        //请求头设定
        headers: {'Content-Type': 'application/json'},
        //请求参数处理
        data: JSON.stringify(data)
    };
    //服务请求的发送
    this.axios(self,this,opts,(res)=>{
        !isTable && this.closeLoading(loading);
        successCallback(res)
    },(err)=>{
        !isTable && this.closeLoading(loading);
        errorCallback && errorCallback(err)
    },url);
}

/**
 * 移动端自定义post请求，对token 包含对token的验证
 * @param self  当前调用的环境对象本身
 * @param url   请求发送地址
 * @param data  请求附带参数
 * @param successCallback   成功回调
 * @param errorCallback 异常回调
 * @param type 导出时的参数设置，若存在则为导出针对接口返回格式
 * @Author yangzeng 20190603 */
defaultParam.wx_post = function(self,url, data,successCallback,errorCallback){
    let _this = this;
    this.getSource(self, this.path_url).then(_ => {
        if(!!url){
            const urlArr = url.split(".");
            const baseUrl = _.data.baseUrl;
            let path = _.data,_index = 0;      
            while(true){
                if((urlArr.length) == _index) break;
                path = path[urlArr[_index]];
                _index += 1;
            }   
            //请求参数设置
            let opts = {
                //请求类型
                method: "post",     
                //请求地址处理
                url: baseUrl + path,     
                //请求头设定   
                headers: {'Content-Type': 'application/json'},   
                //请求参数处理
                data: JSON.stringify(data)        
            };
            _this.axios(self,_this,opts,successCallback,errorCallback,path);
        }
    });
};
//post接口中服务请求的发送，不建议外部使用（仅仅在当前文件内部使用） yangzeng
defaultParam.axios = (self,club,opts,successCallback,errorCallback,path) => {
    //页面返回的参数自定义status中0为成功 ，非0 为失败
    let baseUrl = '';
    let optsUrl = opts.url;
    if(window.location.host.split('.')[0].split('//')[1] == '113' || window.location.host.split('.')[0] == '113'){
        baseUrl = 'http://113.140.81.36:30020';
        opts.url = baseUrl+ '/' + optsUrl.split('://')[1].split('/').slice(1).join('/');
    }
    axios(opts).then(res=>{
        //返回参数结果判断
        if(club.isSuccess(res.status)){
            let _data= res.data;
            //验证数据本身是否按照指定格式传递
            if(typeof _data != "object")  return club.errorMsg(self, "请返回正确格式的参数！");
            //对成功回调的调用
            // if(_data.errcode == 0)  successCallback(_data);
            // else if(_data.errcode != 0) club.errorMsg(self, _data.errmsg);
            successCallback(_data)
        }else if(!!errorCallback && typeof errorCallback == 'function')  errorCallback(err);
    }).catch(err=>{
        //若异常方法在外部声明则进行抛出
        if(!!errorCallback && typeof errorCallback == 'function')  errorCallback(err);
        //未声明异常处理方法，则在公共区域进行处理
        else{
            if(!!err.response){ //err.toString()
                switch(err.response.status){
                    case 400:
                        club.errorMsg(self, "status:400,错误请求,服务器不理解请求的语法！"); 
                        break 
                    case 401:
                        club.errorMsg(self, "status:401,未授权,身份验证失败！");  
                        club.logout(self);
                        break
                    case 403:
                        club.errorMsg(self, "status:403,禁止,服务器拒绝请求");  
                        break
                    case 404:
                        club.errorMsg(self, "status:404,资源丢失,服务器找不到请求资源"); 
                        break;
                    case 405:
                        club.errorMsg(self, "status:405,禁用请求中指定的方法。"); 
                        break
                    case 500:
                        club.errorMsg(self, "status: 500,服务器内部错误,请联系后台接口负责人员！");
                        break;
                    case 501:
                        club.errorMsg(self, "status: 501,服务器不具备完成请求的功能,服务器无法识别请求方法!");
                        break;
                    case 502:
                        club.errorMsg(self, "status: 502,错误网关,服务器收到无效响应!");
                        break;
                    case 503:
                        club.errorMsg(self, "status: 503,服务不可用,服务器目前无法使用（由于超载或停机维护）!");
                        break;
                    case 504:
                        club.errorMsg(self, "status: 504,网关超时,没有及时从上游服务器收到请求!");
                        break;
                    default:
                        club.errorMsg(self, err.toString());
                        break;
                }
            }
        }
    });
};

//开放全部参数设置
defaultParam.http = function(self,url, data,successCallback,errorCallback){
    let access_token = window.localStorage.getItem("user_token"),_this = this;
    //判断token是否存在若不存在则需要重新进行登陆操作
    //登陆成功
    if(!!access_token){     
        let userInfo = window.localStorage.getItem("userinfo");
        userInfo = JSON.parse(userInfo);
        if(data.hasOwnProperty("BOOK_TYPE_CODE") && data.BOOK_TYPE_CODE != ''){}
        else    data["BOOK_TYPE_CODE"] = userInfo.currentDuty.bookTypeCode;
        let opts = {
            method: "post",     
            url: this.path_app+url+"?access_token="+access_token,     
            headers: {
                'Content-Type': 'application/json'
            },    
            data: JSON.stringify({params: data})      
        };
        axios(opts).then(res=>{
            //返回参数结果判断
            if(this.isSuccess(res.status)){
                let _data= res.data;
                if(typeof _data != "object") return _this.errorMsg(self, "请返回正确格式的参数！");
                successCallback(_data);
            }else if(!!errorCallback && typeof errorCallback == 'function')  errorCallback(err);
        }).catch(err=>{
            if(!!errorCallback && typeof errorCallback == 'function')  errorCallback(err);
            else{
                if(!!err.request && err.request.status == 401) {
                    _this.errorMsg(self, "验证失效请重新登陆！"+err.toString());
                    this.logout(self);
                }else if(!!err.request && err.request.status == 500)     _this.errorMsg(self, "参数异常："+err.toString());
                else _this.errorMsg(self, "出现异常："+err.toString());
            }
        });
    }else{
        window.localStorage.clear();    
        self.$router.push("/login");
    }
};
//返回请求的成功与否验证
defaultParam.isSuccess= function(code){
    let successFlg = false;
    switch (code) {
        case 200:
            successFlg = true;
            break;
        case "400":
            break;
        case "401":
            break;
        case "403":
            break;
        case "404":
            break;
        case "500":
            break;
        case "501":
            break;
        case "503":
            break;
    }
    return successFlg;
};

/**
 * 成功消息提醒
 * @param self  调用环境本身
 * @param message   消息内容
 * @Author yangzeng */
defaultParam.successMsg = function(self,message){
    self.$message({
        type: "success",
        message: message,
        showClose: true
    });
};
/**
 * 异常消息提醒
 * @param self  调用环境本身
 * @param message 消息提醒内容
 * @Author yangzeng */
defaultParam.errorMsg = function(self, message){
    self.$message({
        type: "error",
        message: message,
        showClose: true
    });
};
/**
* 警告提醒消息
* @Param self 调用环境
* @Param message 提示消息内容
* @Author yangzeng 20190703
*/
defaultParam.warningMsg = function(self, message){
    self.$message({
        type: "warning",
        message: message,
        showClose: true
    });
};
/**
 * 提示框封装
 * @param self 调用者当前环境对象
 * @param opts 调用的参数 */
defaultParam.confrirm = function(self,opts){
    let type = "warning";
    if(opts.hasOwnProperty("type") && !!opts.type && !["warning", "info", "primary", "danger"].indexOf(opts.type))    type = opts.type;
    self.$confirm(opts.message, "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: type,
        showCancelButton: opts.hasOwnProperty('cancel') ? true : false,
        closeOnClickModal: opts.hasOwnProperty('closeOnClickModal') ? opts.closeOnClickModal : true,
        showClose: opts.hasOwnProperty('showClose') ? opts.showClose : true,
        closeOnPressEscape: opts.hasOwnProperty('closeOnPressEscape') ? opts.closeOnPressEscape : true,
    }).then(() => {
        if(opts.hasOwnProperty("ok"))   opts.ok();
    }).catch(() => {
        if(opts.hasOwnProperty("cancel"))   opts.cancel();
    });
}
/**
 * 提示框封装pro
 * @param self 调用者当前环境对象
 * @param opts 调用的参数 
 * @param type 弹窗类型
 */
defaultParam.confrirmPro = function(self,opts,type){
    self.$confirm(opts.message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: type ? type : 'info'
    }).then(() => {
        if(opts.hasOwnProperty("ok"))   opts.ok();
    }).catch(() => {
        if(opts.hasOwnProperty("cancel"))   opts.cancel();
    });
}
/**
 * 对参数左右空字符串的处理
 * @param val   需要去除空字符的参数对象(String)
 * @constructor */
defaultParam.removeEmptyString = function(val){
    return val.replace(/^\s+|\s+$/g,"");
};
/**
 * 是否是数字的判断
 * @param val
 * @author yangzeng */
defaultParam.isNumber = function(val){
    return !isNaN(val);
};
/**
 * 金额千分位的转换
 * @param data
 * @author yangzeng */
defaultParam.numberToMoney = function(data){
    if(!!data && !isNaN(data)){
        amount = data.split(".");
        let leftStr = amount[0],newLeftStr='';
        while(true){
            if(leftStr == "") break;
            if(leftStr.length > 3){
                if(newLeftStr.length > 0){
                    newLeftStr = leftStr.substr(leftStr.length-3,leftStr.length)+ ',' + newLeftStr;         
                }else newLeftStr = leftStr.substr(leftStr.length-3,leftStr.length);
            }else newLeftStr = leftStr + ',' + newLeftStr;
            leftStr = leftStr.substr(0,leftStr.length - 3);
        }
        newLeftStr = amount[1] == undefined ? newLeftStr : newLeftStr + "." + amount[1];
        if(newLeftStr.substr(newLeftStr.length - 1 , newLeftStr.length) == ","){
            newLeftStr = newLeftStr.substr(0,newLeftStr.length - 1);
        }
        return newLeftStr;
    }else return data;
};
/**
 * 千分位转换为数字
 * @param data
 * @author yangzeng */
defaultParam.moneyToNumber = function(data){
    let dataArr = data.split(",");
    return dataArr.json("");
};
/**
 * 时间戳转日期格式
 * @param data
 * @Author yangzeng
 * @constructor */
defaultParam.DateFormat = function(data){
    let d = new Date(data);
    let year = d.getFullYear();
    let month = d.getMonth() + 1;
    let day = d.getDate() <10 ? '0' + d.getDate() : '' + d.getDate();
    return  year+ '-' + month + '-' + day;
};
/**
 * 时间戳转日期时间字符串
 * @param data
 * @returns {string}
 * @Author yangzeng
 * @constructor */
defaultParam.DateTimeFormat = function(data){
    if(!data) return null;
    let d = new Date(data);
    let year = d.getFullYear();
    let month = d.getMonth() + 1<10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1;
    let day = d.getDate() <10 ? '0' + d.getDate() : d.getDate();
    let hour = d.getHours()<10 ? '0' + d.getHours() : d.getHours();
    let minutes = d.getMinutes()<10 ? '0' + d.getMinutes() : d.getMinutes();
    let seconds = d.getSeconds()<10 ? '0' + d.getSeconds() : d.getSeconds();
    return  year+ '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds;
};
/**
 * 获取指定类型的参数： 
 * @param data {date: timers, forMat: year}   
 *      forMat: 年-year
 *              月-month
 *              日-day
 *              小时-hour
 *              分钟-minute
 *              秒-second
 * @Authro yangzeng
 * @constructor */
defaultParam.getForMatDate = function(date,forMat){
    let d = new Date(date),result;
    switch(forMat){
        case 'year':
            result = d.getFullYear();
            break;
        case 'month':
            result = d.getMonth() + 1;
            break;
        case 'day':
            result = d.getDate() <10 ? '0' + d.getDate() : '' + d.getDate();
            break;
        case 'hour':
            result = d.getHours();
            break;
        case 'minute':
            result = d.getMinutes();
            break;
        case 'second':
            result = d.getSeconds();
            break;
    }
    return  result;
};
/**
 * 退出登陆
 * @param self  调用环境本身
 * @Author yangzeng */
defaultParam.logout = function(self){
    window.localStorage.clear();
    self.$router.push({
        path:"/login",
        query:{
            redirect:self.$route.fullPath
        }
    });
};
/**
 * 开启指定数据的行编辑操作
 * @data 当前提交的源数据
 * @arr 转换参数指定的key
 * @Author yangzeng 
 * @Date 20190716 */
defaultParam.converRowEditData = function(data, arr){
    let result = new Array(),obj;
    data.forEach(_ => {
        obj = new Object()
        Object.keys(_).forEach(key => {
            if(arr.includes(key)) obj[key] = {"isEdit": false, "value": _[key]};
            else obj[key] = !!_[key] ? _[key]: null;
        });
        result.push(obj);
    });
    return result;
};
/**
 * 把指定行编辑数据修改为提交参数形式
 * @data 转换源数据
 * @arr 转换的键值指定
 * @Author yangzeng 
 * @Date 20190716 */
defaultParam.converRequestData = function(data){
    let result = new Array(),obj;
    data.forEach(_ => {
        obj = new Object();
        Object.keys(_).forEach(key => {
            if(_[key] instanceof Object && _[key].hasOwnProperty("value")) {
                obj[key] = _[key].value;
            }else {
                obj[key] = _[key];
            }
        });
        result.push(obj);
    });
    return result;
};

/**
 * 把 AA_BB_CC 类型大写数据转换为驼峰命名格式
 * @data 转换源数据 [{key: value,key: value},{key: value,key: value},...]
 * @Author yangzeng 
 * @Date 20190720 */
defaultParam.converToLower = function(data){
    if(data instanceof Array && data.length >0){
        let newData = [],obj = {};
        data.forEach(_ => {
            obj = {};
            Object.keys(_).forEach(key => {
                let lowerKey = key.toLocaleLowerCase();
                let keyArr = lowerKey.split("_");
                let firstStr,lastStr,newKey;
                for(let i in keyArr){
                    if(i > 0){
                        firstStr = keyArr[i].substr(0,1);
                        lastStr = keyArr[i].substr(1,keyArr[i].length - 1);
                        newKey += firstStr.toUpperCase() + lastStr;
                    }else newKey = keyArr[i];
                }
                obj[newKey] = _[key];
            });
            newData.push(obj);
        });
        return newData;
    }else return "请传入正确格式参数！";
}

/**
 * 简单数组的去重操作 
 * @param _[Array] 当前去重的数组对象 ['a','b','a']
 * @return 去重之后的数组对象
 * @Author yangzeng */
defaultParam.repeatArray = function(_){
    if(_ instanceof Array){
        let result = [];
        _.forEach(e => {
            if(!result.includes(e))   result.push(e);
        });
        return result;
    }else return "当前方法仅仅接收数组参数";
};
/**
 * 对象数组的去操作
 * @param data[Array] 去重操作的对象数组  [{key: value...},...]
 * @param key[String] 指定相同条件的key，用作参数相等的判断   keyName
 */
defaultParam.repeatObjectList = (data,key) => {
    if(data instanceof Array && typeof key == "string"){
        let result = [],keyVal=[];
        data.forEach(_ => {
            if(!keyVal.includes(_[key])){
                result.push(_);
                keyVal.push(_[key]);
            };
        });
        return result;
    }else return "请输入正确的参数";
};
/**
 * 本地静态资源的调用，默认资源需放在public下
 * @Param self 当前调用的环境对象
 * @param filePath 调用的当前文件路径
 * @Returns Promise 当前请求的数据结果，需使用'.then()'进行数据解析
 */
// defaultParam.getSource = async (self,filePath) => {
//     return await self.$axios.get(filePath);
// };

/**
 * 时间戳转日期格式--年月
 * @param self 调用者当前环境对象
 * @Author leichao
 * @constructor */
defaultParam.getTime = function (self) {
    let date = new Date();
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    let time = y + "-" + m;
    self.formInline.form2 = time;
}
defaultParam.timeConversion = function (date) {
    if(!date) return null;
    let dateTime = date instanceof Date ? date : new Date(date);
    var y=dateTime.getFullYear();
    var m=dateTime.getMonth()+1;
    var d=dateTime.getDate();
    var hh=dateTime.getHours();
    var mm=dateTime.getMinutes();
    var ss=dateTime.getSeconds();
    m = m<10?("0"+m):m;
    d = d<10?("0"+d):d;
    hh = hh<10?("0"+hh):hh;
    mm = mm<10?("0"+mm):mm;
    ss = ss<10?("0"+ss):ss;
    return y+''+m+''+d+''+hh+''+mm+''+ss;
}
/**
 * 检查管理单位等级
 * @param self 调用者当前环境对象
 * @param callback 回调
 * @Author weiyuyang
 * @constructor */
defaultParam.checkLevel = function (self,callback,orgIdPar) {
    let _this=this
    _this.getSource(self, _this.base_config).then(res => {
        if(res.status == 200){
            let userInfo = JSON.parse(window.localStorage.getItem("userinfo"));
            let config = res.data;
            let timer = (new Date()).getTime();
            let token = self.$md5(userInfo.accessToken+config.app.appScrect+config.app.appName+timer);
            //地址参数的报装、判断当前是否存在param参数类型
            let _url=config.base.baseUrl+'/supportservice/orgInfo';
            let baseUrl
            if(window.location.host.split('.')[0].split('//')[1] == '113' || window.location.host.split('.')[0] == '113'){
                baseUrl = 'http://113.140.81.36:30020';
                _url = baseUrl+'/supportservice/orgInfo'
            }
            let orgId=orgIdPar?orgIdPar:userInfo.orgId
            _url += '?orgId='+orgId+'&token='+token+"&accessToken="+userInfo.accessToken+"&userId="+userInfo.userId+"&timeStamp="+timer+"&appSecret="+config.app.appScrect;
            axios({ // 用axios发送post请求
                method: 'post',
                url: _url, // 请求地址
            }).then((resp) => { 
                callback(resp.data.data)
            })
        }
    })

    
}
/**
 * 弹框提示
 * @param array 选中数组
 * @param self 调用者当前环境对象        
 * @Author leichao
 * @constructor */
defaultParam.checkSelection = function (self,array) {
    if (array && array.length) return true;
    else {
        defaultParam.confrirm(self,{message: "请选择需要操作的数据！"});
    }
}
/**
 * 下载api
 */
defaultParam.downloadByPost = function (self,url,param) {
    let userInfo = JSON.parse(window.localStorage.getItem("userinfo"));
    let timer = (new Date()).getTime();
    let token = self.$md5(userInfo.accessToken+this.appScrect+this.appName+timer);
    let _url = this.baseUrl+url;
    _url += '?appNo='+param.appNo+'&token='+token+"&accessToken="+userInfo.accessToken+"&userId="+userInfo.userId+"&timeStamp="+timer+"&appSecret="+this.appScrect;
    axios({ // 用axios发送post请求
        method: 'post',
        url: _url, // 请求地址
        responseType: 'blob' // 表明返回服务器返回的数据类型
    }).then((resp) => { // 处理返回的文件流
        if (!resp) {
            return
        }
        let url = window.URL.createObjectURL(new Blob([resp.data])) // 这里一定要使用resp.data的内容，否则excel中的内容为: [object][object], 而非实际的模板内容
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', 'excel.xls')
        document.body.appendChild(link)
        link.click()
    })
}

 /** 加载中的等待功能，
  * @param txt 显示的提示内容
  * @Author yangzeng 20200731*/
defaultParam.openLoading = function(txt){
    let text = !!txt ? txt : "loaidng 。。。";
    return Loading.service({
        fullscreen: true,
        text: text,
        background: 'rgba(0, 0, 0, 0.35)'
    });
}
defaultParam.closeLoading = function(obj){
    if(!!obj) {
        setTimeout(_ => {
            obj.close();
        },300);
    }
}

import axios from 'axios';
import { async } from 'q';
import { Loading } from 'element-ui';
export default defaultParam;